package client;

import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import javax.swing.JPanel;

import partie.Joueur;
import partie.PaquetCartesDobble;

public class PanelCarte{
	
	JPanel carte; 
	GridBagConstraints gbc_carte;
	int indexCarte;
	InterfaceClientGUI interfaceClient;
	
	JPanel image_1;
	JPanel image_2;
	JPanel image_3;
	JPanel image_4;
	JPanel image_5;
	JPanel image_6;
	
	LabelImage lblLabelImage_1;
	LabelImage lblLabelImage_2;
	LabelImage lblLabelImage_3;
	LabelImage lblLabelImage_4;
	LabelImage lblLabelImage_5;
	LabelImage lblLabelImage_6;
	
	public PanelCarte(InterfaceClientGUI interfaceClient){
		indexCarte = 0;
		this.interfaceClient = interfaceClient;
		carte = new JPanel();
		gbc_carte = new GridBagConstraints();
		gbc_carte.fill = GridBagConstraints.BOTH;
		gbc_carte.gridx = 0;
		gbc_carte.gridy = 1;
		carte.setLayout(new GridLayout(2, 3, 0, 0));
		
		image_1 = new JPanel();
		carte.add(image_1);
		
		image_2 = new JPanel();
		carte.add(image_2);
		
		image_3 = new JPanel();
		carte.add(image_3);
		
		image_4 = new JPanel();
		carte.add(image_4);
		
		image_5 = new JPanel();
		carte.add(image_5);
		
		image_6 = new JPanel();
		carte.add(image_6);
		
		lblLabelImage_1 = new LabelImage(this.interfaceClient);
		image_1.add(lblLabelImage_1.lblLabelImage);
	
		lblLabelImage_2 = new LabelImage(this.interfaceClient);
		image_2.add(lblLabelImage_2.lblLabelImage);
		
		lblLabelImage_3 = new LabelImage(this.interfaceClient);
		image_3.add(lblLabelImage_3.lblLabelImage);
				
		lblLabelImage_4 = new LabelImage(this.interfaceClient);
		image_4.add(lblLabelImage_4.lblLabelImage);
		
		lblLabelImage_5 = new LabelImage(this.interfaceClient);
		image_5.add(lblLabelImage_5.lblLabelImage);
		
		lblLabelImage_6 = new LabelImage(this.interfaceClient);
		image_6.add(lblLabelImage_6.lblLabelImage);
	}
	
	public void setCarte(int colonneCarte) {
		
		indexCarte = colonneCarte;	
		int[] image = PaquetCartesDobble.getIndexImage(colonneCarte);		
		lblLabelImage_1.setIndexImage(image[0]);
		lblLabelImage_2.setIndexImage(image[1]);
		lblLabelImage_3.setIndexImage(image[2]);
		lblLabelImage_4.setIndexImage(image[3]);
		lblLabelImage_5.setIndexImage(image[4]);
		lblLabelImage_6.setIndexImage(image[5]);		
		this.carte.validate();
	}
	
	public void setCarte(Joueur joueurDeLaCarteQuiVaChanger, Joueur joueurDuClient) {
		
		indexCarte = joueurDeLaCarteQuiVaChanger.getIdCarte();	
		int[] image = PaquetCartesDobble.getIndexImage(indexCarte);		
		lblLabelImage_1.setIndexImage(joueurDeLaCarteQuiVaChanger, joueurDuClient, image[0]);
		lblLabelImage_2.setIndexImage(joueurDeLaCarteQuiVaChanger, joueurDuClient, image[1]);
		lblLabelImage_3.setIndexImage(joueurDeLaCarteQuiVaChanger, joueurDuClient, image[2]);
		lblLabelImage_4.setIndexImage(joueurDeLaCarteQuiVaChanger, joueurDuClient, image[3]);
		lblLabelImage_5.setIndexImage(joueurDeLaCarteQuiVaChanger, joueurDuClient, image[4]);
		lblLabelImage_6.setIndexImage(joueurDeLaCarteQuiVaChanger, joueurDuClient, image[5]);		
		this.carte.validate();
	}
	
	public void resetCarte(){
		indexCarte = -1;	
		lblLabelImage_1.setIndexImage(indexCarte);
		lblLabelImage_2.setIndexImage(indexCarte);
		lblLabelImage_3.setIndexImage(indexCarte);
		lblLabelImage_4.setIndexImage(indexCarte);
		lblLabelImage_5.setIndexImage(indexCarte);
		lblLabelImage_6.setIndexImage(indexCarte);		
		this.carte.validate();
	}
	
	
}
